﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BabyFood.Entities;
using BabyFood.Data;
using System.Data;

public partial class Controls_ThuVienAnh : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (!Page.IsPostBack)
        //{
        //    Pager1.CurrentIndex = 1;
        //    Bind_Data(Pager1.CurrentIndex);
        //}
        Pager1.CurrentIndex = 1;
        HienThiSachHay(Pager1.CurrentIndex);
    }

    private void HienThiSachHay(int PageNo)
    {
        int TotalRows = 0;
        string WhereClause = "1=1 and TrangThai=1";
        DataSet dsBST = DataRepository.Provider.ExecuteDataSet("BoSuuTap_GetPaged", WhereClause, "NgayCapNhat DESC", PageNo - 1, Pager1.PageSize);

        dlBST.DataSource = dsBST.Tables[0];
        dlBST.DataBind();
        try
        {
            TotalRows = Convert.ToInt32(dsBST.Tables[1].Rows[0][0]);
        }
        catch (Exception)
        {
        }
        Pager1.ItemCount = TotalRows;
        if (TotalRows <= Pager1.PageSize)
            Pager1.Visible = false;
        else
            Pager1.Visible = true;
    }
    protected void Pager1_Command(object sender, CommandEventArgs e)
    {
        int currnetPageIndex = Convert.ToInt32(e.CommandArgument);
        Pager1.CurrentIndex = currnetPageIndex;
        HienThiSachHay(currnetPageIndex);
    }

    public string GetLienKets(object LienKet)
    {
        //if (Session["KhachHangVip"] != null)
        //{
        return Server.HtmlDecode(LienKet.ToString());
        //    }
        //    else
        //        return "Bạn phải đăng nhập";
    }
    //protected void Bind_Data2(int PageNo)
    //{
    //    int TotalRows = 0;
    //    string WhereClause = "IdBoSuuTap=" + H_IdBoSuuTap.Value;
    //    TList<HinhAnh> TList_Catalog = DataRepository.HinhAnhProvider.GetPaged(WhereClause, "NgayCapNhat DESC", PageNo - 1, Pager2.PageSize, out TotalRows);
    //    dlHinhAnh.DataSource = TList_Catalog;
    //    dlHinhAnh.DataBind();

    //    Pager2.ItemCount = TotalRows;
    //    if (TotalRows <= Pager2.PageSize)
    //        PanelPaging.Visible = false;
    //    else
    //        PanelPaging.Visible = true;
    //}

    //protected void Bind_Data(int PageNo)
    //{
    //    int TotalRows = 0;
    //    string WhereClause = "1=1";
    //    TList<BoSuuTap> TList_Catalog = DataRepository.BoSuuTapProvider.GetPaged(WhereClause, "NgayCapNhat DESC", PageNo - 1, Pager1.PageSize, out TotalRows);
    //    dlSoBuuTap.DataSource = TList_Catalog;
    //    dlSoBuuTap.DataBind();
    //    Pager1.ItemCount = TotalRows;
    //    H_PageCount.Value = Pager1.PageCount.ToString();
    //}

    //public string GetHinhAnhThumb(object Ten)
    //{
    //    return Common.sPathUpBoSuuTap + "/" + H_IdBoSuuTap.Value + "/Thumb/" + Ten;
    //}

    //public string GetHinhAnhFull(object Ten)
    //{
    //    return "Upload/BoSuuTap/" + H_IdBoSuuTap.Value + "/Full/" + Ten;
    //}

    //protected void Pager2_Command(object sender, CommandEventArgs e)
    //{
    //    try
    //    {
    //        int currnetPageIndex = Convert.ToInt32(e.CommandArgument);
    //        Pager2.CurrentIndex = currnetPageIndex;
    //        Bind_Data2(currnetPageIndex);
    //    }
    //    catch (Exception ex)
    //    {
    //        Common.WriteLog("AnhDep.aspx.cs", "Pager1_Command()", ex.ToString());
    //    }
    //}

    public string GetImageBoSuuTap(object IdBoSuuTap)
    {
        int TotalRows = 0;
        TList<HinhAnh> Tlist_HinhAnh = DataRepository.HinhAnhProvider.GetPaged("IdBoSuuTap='" + IdBoSuuTap + "'", "NgayCapNhat DESC", 0, 1, out TotalRows);
        return Tlist_HinhAnh.Count > 0 ? Common.sPathUpBoSuuTap + "/" + IdBoSuuTap + "/Thumb/" + Tlist_HinhAnh[0].AnhDaiDien : "~/Images/no_image.jpg";
    }

    //protected void Pager1_Command(object sender, CommandEventArgs e)
    //{
    //    try
    //    {
    //        int currnetPageIndex = Convert.ToInt32(e.CommandArgument);
    //        Pager1.CurrentIndex = currnetPageIndex;
    //        Bind_Data(Pager1.CurrentIndex);
    //    }
    //    catch (Exception ex)
    //    {
    //        Common.WriteLog("AnhDep.aspx.cs", "Pager1_Command()", ex.ToString());
    //    }
    //}

    //protected void cmdNext_Click(object sender, ImageClickEventArgs e)
    //{
    //    if (Pager1.CurrentIndex < Convert.ToInt32(H_PageCount.Value))
    //    {
    //        Pager1.CurrentIndex = Pager1.CurrentIndex + 1;
    //        Bind_Data(Pager1.CurrentIndex);
    //    }
    //}

    //protected void cmdPrevious_Click(object sender, ImageClickEventArgs e)
    //{
    //    if (Pager1.CurrentIndex > 1)
    //    {
    //        Pager1.CurrentIndex = Pager1.CurrentIndex - 1;
    //        Bind_Data(Pager1.CurrentIndex);
    //    }
    //}
    public string GetTieuDe(object Char)
    {
        string s = Char.ToString();
        return Common.ConvertToUnSign(s);
    }
}
